package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.mapper.BlackListMapper;
import com.itheima.service.db.BlackListService;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author Guanxing
 * @date 2021/9/21
 */
@Service
public class BlackServiceImpl implements BlackListService {

    @Autowired
    private BlackListMapper blackListMapper;

    //查询黑名单数据
    @Override
    public PageBeanVo findBlackUserByUserId(Long id, Integer pageNum, Integer pageSize) {
        //开启分页
        IPage page = new Page(pageNum, pageSize);

        //调用查询分页
        page = blackListMapper.findBlackListUserByUid(page, id);

        return new PageBeanVo(pageNum,pageSize,page.getTotal(),page.getRecords());
    }

    //删除黑名单用户信息
    @Override
    public void deleteBlackUser(Long loginUserId,Long blackUserId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id",loginUserId);
        queryWrapper.eq("black_user_id" ,blackUserId );
        blackListMapper.delete(queryWrapper);
    }
}
